home *** CD-ROM | disk | FTP | other *** search
- Path: nova.umuc.edu!nova!ldigiova
- From: Larry DiGiovanni <ldigiova@nova.umuc.edu>
- Newsgroups: comp.lang.c
- Subject: Arrays of strings
- Date: Wed, 7 Feb 1996 14:23:19 -0500
- Organization: University of Maryland University College
- Message-ID: <Pine.SOL.3.91.960207141605.27357A-100000@nova>
- NNTP-Posting-Host: nova.umuc.edu
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=US-ASCII
- X-Sender: ldigiova@nova
-
-
- I'm trying to read lines of a text file and load those lines into an
- array. I have a couple of questions...
-
- 1. How do I declare the array to contain the text. When it is declared,
- I will not know how many lines are in the text file. char **txtarray?
-
- 2. How do I allocate the space for the data once I know how many lines
- are in the text file? txtarray = malloc((size_t)(nelements))?
-
- 3. What is the best way to read from the text file into the array
- elements? fscanf? fgets? I have had no success reading directly into the
- elements with these two functions. I don't understand why, but it may be
- related to my poor understanding of (1) and (2) above as well.
-
- Any help would be greatly appreciated. TIA
-
- Larry DiGiovanni
-
-